﻿<!DOCTYPE html>
<!--试题管理编辑-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

    <link href="../static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="../static/js/vue-treeselect/vue-treeselect.js"></script>
    <!-- 行内编辑 css-->
    <style>
        .tb-edit .el-input {
            display: none
        }

        .tb-edit .current-row .el-input {
            display: block
        }

            .tb-edit .current-row .el-input + span {
                display: none
            }

        .tb-edit .el-select {
            display: none
        }

        .tb-edit .current-row .el-select {
            display: block
        }

            .tb-edit .current-row .el-select + span {
                display: none
            }

        .xian {
            display: block;
            text-align: center;
        }

        .yin {
            display: none;
            text-align: center;
        }

        .lineMust {
            position: absolute;
            right: 15px;
            bottom: 2px;
            bottom: 3px\0 !important;
            /* 兼容ie */
        }
    </style>
    <!-- 行内编辑 css-->
</head>

<body>
    <div id="app" v-cloak class="popupW50">
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px"
                 size="mini">
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item prop="questionManagementContent" >
                            <el-input type="text" v-model="Form.questionManagementContent" autocomplete="off"
                                      size="mini">
                                <template slot="prepend">
                                    {{QuestionManagement.QuestionManagementContent+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.questionManagementContent">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item prop="questionManagementType">
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{QuestionManagement.QuestionManagementType+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.questionManagementType" slot="suffix"
                                           :placeholder="QuestionManagement.QuestionManagementType">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in QuestionManagementTypeList" :label="item.value"
                                               :value="item.key">
                                    </el-option>
                                </el-select>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.questionManagementType">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item prop="degreeOfDifficulty">
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{QuestionManagement.DegreeOfDifficulty+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.degreeOfDifficulty" slot="suffix"
                                           :placeholder="QuestionManagement.DegreeOfDifficulty">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in DegreeOfDifficultyList" :label="item.value"
                                               :value="item.key">
                                    </el-option>
                                </el-select>
                            </el-input>

                            <span class="iputLineMust" v-if="!Form.degreeOfDifficulty">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>

                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item prop="courseware">
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{QuestionManagement.Courseware+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.trainingcourse" slot="suffix"
                                           :placeholder="QuestionManagement.Courseware">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in Courseware" :label="item.coursewareName" :value="item.id">
                                    </el-option>
                                </el-select>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.trainingcourse">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <el-row>
                <el-col class="head-tool">
                    <!--<el-button type="primary" @click="UserInput('tj')">{{col.btnAddItem}}</el-button>-->
                    <btn :text="col.btnAdd" linetype="4" @click="add"></btn>
                </el-col>
            </el-row>
            <el-row>
                <el-col>
                    <!--<el-table :data="Form.OptionsList" border>
        <el-table-column prop="OptionName" :label="QuestionManagementOption.OptionName">
        </el-table-column>
        <el-table-column prop="OptionComment" :label="QuestionManagementOption.OptionComment">
        </el-table-column>
        <el-table-column prop="" align="center" label="答案">
            <template slot-scope="scope">
                <el-select @visible-change="visibleChange" @change="handleSelect" v-model="scope.row.IsAnswer" placeholder="请选择">
                    <el-option v-for="item in QuestionManagementOptionsList" :key="item.key"
                               :label="item.value" :value="item.key"></el-option>
                </el-select>
            </template>
        </el-table-column>

        <el-table-column label="操作">
            <template slot-scope="scope">
                <el-button @click.native.prevent="deleteRow(scope.$index, Form.OptionsList)" type="text"
                           size="small">
                    移除
                </el-button>
            </template>
        </el-table-column>
    </el-table>-->
                    <!--表格开始-->
                    <el-table ref="table" stripe @current-change="tableHandleCurrentChange" class="tb-edit"
                              :data="Form.pX_QuestionsOptions" :row-key="getRowKeys" border
                              @selection-change="handleSelectionChange" row-style="height:10px" style="width: 100%;">

                        <el-table-column prop="optionName" show-overflow-tooltip="true"
                                         :label="QuestionManagementOption.OptionName">
                            <template scope="scope">
                                <el-select @visible-change="visibleChange" v-model="scope.row.optionName" placeholder="请选择" size="mini">
                                    <el-option label="A" value="A"></el-option>
                                    <el-option label="B" value="B"></el-option>
                                    <el-option label="C" value="C"></el-option>
                                    <el-option label="D" value="D"></el-option>
                                </el-select>
                                <span>{{scope.row.optionName}}</span>
                            </template>
                        </el-table-column>


                        <el-table-column prop="optionComment" :label="QuestionManagementOption.OptionComment"
                                         show-overflow-tooltip="true">
                            <template scope="scope">
                                <el-input size="mini" v-model="scope.row.optionComment" placeholder="请输入内容">
                                </el-input>
                                <span>{{scope.row.optionComment}}</span>
                            </template>
                        </el-table-column>

                        <el-table-column prop="isAnswer" :label="QuestionManagementOption.IsAnswer"
                                         show-overflow-tooltip="true">
                            <template scope="scope">
                                <el-select @visible-change="visibleChange" v-model="scope.row.isAnswer" placeholder="请选择" size="mini">
                                    <el-option label="是" value="是"></el-option>
                                    <el-option label="否" value="否"></el-option>
                                </el-select>
                                <span>{{scope.row.isAnswer}}</span>
                            </template>
                        </el-table-column>





                        <el-table-column width="90" prop="update" label="编辑">
                            <template slot-scope="scope">
                                <span class="start xian">
                                    <button type="button" class="elst-bt-xg"
                                            @click=Edit('xg',scope.row.id,scope.$index)>
                                        <i class="el-icon-edit"></i>
                                    </button>
                                </span>
                                <span class="end yin">
                                    <button type="button" class="elst-bt-xg " @click="Save(scope.$index, scope.row)">
                                        <i class="el-icon-circle-check-outline"></i>
                                        <!-- 保存 -->
                                    </button>
                                   
                                    <button type="button" class="elst-bt-xg " @click="Back(scope.$index, scope.row)">
                                        <i class="el-icon-circle-close-outline"></i>
                                        <!-- 撤销 -->
                                    </button>
                                </span>
                            </template>
                        </el-table-column>

                        <el-table-column width="53" label="操作" fixed="right">
                            <template slot-scope="scope">
                                <button type="button" class="elst-bt-xg" @click="deleteRow(scope.$index, Form.pX_QuestionsOptions)">
                                    <i class="el-icon-delete"></i>
                                </button>
                            </template>
                        </el-table-column>


                    </el-table>
                    <!--表格结束-->

                </el-col>
            </el-row>
            <br>
            <el-row type="flex" justify="end">
                <el-form-item>
                    <!--<el-button type="primary" @click="onsubmitform('ruleform')">{{col.btnsave}}</el-button>-->
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
        <el-dialog title="试题选项" fullscreen="true" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="50%" height="50%"
                   top="10vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:280px;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">
        Vue.component('treeselect', VueTreeselect.Treeselect)
        var app = new Vue({
            el: '#app',
            data: {
                id: '',
                //业务表单内容
                Form: {
                    id: guidEmpty,
                    QuestionManagementContent: '',//"试题内容"
                    QuestionManagementType: '', //试题类型
                    DegreeOfDifficulty: '',//难易程度
                    Answer: '',//答案
                    Courseware: '',
                    editorTime: '',
                    CoursewareID: null,//课件类型ID
                    pX_QuestionsOptions: [],//选项
                    pid: null

                },
                ListItem: ListItem,
                options: [],
                QuestionManagementOptionsList: [],
                mydata: QuestionManagementTree,
                QuestionManagementTypeList: [],//试题类型
                DegreeOfDifficultyList: [],
                Courseware: [],
                //表单验证
                rules: {
                    questionManagementContent: [
                        verification.NotNull,
                        //{ pattern: verification.StringLengthAtoB.t.format(2, 5), message: verification.StringLengthAtoB.m.format(2, 5), trigger: 'blur' }
                    ],
                    questionManagementType: [
                        verification.NotNull,
                        //{ pattern: verification.StringLengthAtoB.t.format(5, 50), message: verification.StringLengthAtoB.m.format(5, 10), trigger: 'blur' }
                    ],
                    degreeOfDifficulty: [
                        verification.NotNull,
                        //{ pattern: verification.StringLengthAtoB.t.format(2, 5), message: verification.StringLengthAtoB.m.format(2, 5), trigger: 'blur' }
                    ],
                    trainingcourse: [
                        verification.NotNull,
                        //{ pattern: verification.StringLengthAtoB.t.format(5, 50), message: verification.StringLengthAtoB.m.format(5, 10), trigger: 'blur' }
                    ],
                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },

                // 行内编辑 js
                add: function (formName) {
                    //if (this.formInline.model.classification == undefined) {
                    //    showMessage('必须选择评估类型!', 'error'); return;
                    //}
                    //alert('xxxxxxx');
                    if ($('tbody tr').attr("class") == "el-table__row current-row") {
                        showMessage(msg.EditingNotCompleted, 'error');
                    } else {

                        $('.el-table__row').removeClass('current-row');
                        $('.el-table__row span.end').removeClass('xian');
                        $('.el-table__row span.end').addClass('yin');
                        $('.el-table__row span.start').removeClass('yin');
                        $('.el-table__row span.start').addClass('xian');

                        //if (!this.Form.employmentLicenseList) {
                        //    this.Form.employmentLicenseList = [];
                        //}

                        //debugger;

                        var newObj = {
                            optionName: '',//添加是清空录入数据的，每一项都要有
                            optionComment: '',//添加是清空录入数据的，每一项都要有
                            isAnswer: '',//添加是清空录入数据的，每一项都要有
                        }
                        this.Form.pX_QuestionsOptions.unshift(newObj);
                        //this.Form.employmentLicenseList.unshift(this.Form);


                        setTimeout(function () {
                            $('.el-table__row:eq(0)').addClass('current-row');
                            $('.el-table__row:eq(0) span.end').removeClass('yin');
                            $('.el-table__row:eq(0) span.end').addClass('xian');
                            $('.el-table__row:eq(0) span.start').removeClass('xian');
                            $('.el-table__row:eq(0) span.start').addClass('yin');
                        }, 100);
                    }
                },
                //修改
                Edit: function (val, id, index) {
                    $('.el-table__row').removeClass('current-row');
                    $('.el-table__row:eq(' + index + ')').addClass('current-row');
                    $('.el-table__row span.end').removeClass('xian');
                    $('.el-table__row span.end').addClass('yin');
                    $('.el-table__row span.start').removeClass('yin');
                    $('.el-table__row span.start').addClass('xian');
                    $('.el-table__row:eq(' + index + ') span.end').removeClass('yin');
                    $('.el-table__row:eq(' + index + ') span.end').addClass('xian');
                    $('.el-table__row:eq(' + index + ') span.start').removeClass('xian');
                    $('.el-table__row:eq(' + index + ') span.start').addClass('yin');
                },
                // 保存 注意去掉mock中的parent 否则无法保存
                Save: function (a, b) {
                    if (!b.optionName || !b.optionComment || !b.isAnswer) {
                         showMessage(msg.NoMust, 'error');
                    }
                    else {

                        var c = 0;
                        var d = 0;
                        var num = 0;
                        
                        for (var i = 0; i < this.Form.pX_QuestionsOptions.length; i++) {

                           
                            if (this.Form.pX_QuestionsOptions[i].optionName == b.optionName) {
                                c +=1 ;

                            }
                            if (this.Form.pX_QuestionsOptions[i].optionComment == b.optionComment) {
                                d += 1;
                            }


                        }

                        if (d>1) {
                            showMessage('请勿添加重复的内容选项！', 'error');
                            return false;

                        }

                        if (c>1) {

                            showMessage('请勿添加重复选项！', 'error');
                            return false;

                        }

                        $('.el-table__row').removeClass('current-row');
                        $('.el-table__row span.end').removeClass('xian');
                        $('.el-table__row span.end').addClass('yin');
                        $('.el-table__row span.start').removeClass('yin');
                        $('.el-table__row span.start').addClass('xian');

                    }
                },
                Back: function (a, b) {
                    $('.el-table__row').removeClass('current-row');
                    $('.el-table__row span.end').removeClass('xian');
                    $('.el-table__row span.end').addClass('yin');
                    $('.el-table__row span.start').removeClass('yin');
                    $('.el-table__row span.start').addClass('xian');
                    
                    this.Form.pX_QuestionsOptions.splice(0, 1);

                    //this.getData();
                },

                handblur: function () {
                    //this.$refs.table.setCurrentRow(999);
                    //console.log("c", 'c');
                },
                //table选中行handle
                tableHandleCurrentChange: function (currentRow) {
                    this.currSeelctId = currentRow.id;
                    this.currSeelctCell = currentRow;
                },
                // 行内编辑 js
                indexMethod: function (index) {
                    return (this.ListItem.currentPage - 1) * this.ListItem.pagesize + index + 1;
                },



                //关闭Dialog 回调
                // closeDialog: function () { closeDialog(this); },

                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                handleChange: function (value) {
                    console.log(value);
                },
                handleSelect: function (ev) {
                    console.log(ev);
                },
                deleteRow: function (index, rows) {
                    rows.splice(index, 1);
                },

                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {

          
                            //判断是否有题目
                            if (mythis.Form.pX_QuestionsOptions.length <= 1) {

                                showMessage('请添加选项信息！', 'error');
                                return false;

                            }
                            var num = 0;
                            for (var i = 0; i < mythis.Form.pX_QuestionsOptions.length; i++) {
                                if (mythis.Form.pX_QuestionsOptions[i].isAnswer == "是") {
                                    num++;
                                }

                            }
                            //判断是否有正确选项
                            if (num == 0) {
                                showMessage('请至少添加一个正确的选项！', 'error');
                                return false;

                            }

                            //判断如果非多选 则不能有多个正确选项
                            if (mythis.Form.questionManagementType != '1' && num > 1) {
                                showMessage('非多选题目只能有一个正确选项！', 'error');
                                return false;

                            }
                            //如果是判断题 只能有两个选项
                            if (mythis.Form.questionManagementType == '2' && mythis.Form.pX_QuestionsOptions.length != 2) {
                                showMessage('判断题只能有两个选项！', 'error');
                                return false;

                            }



                            onSubmitForm(this, '/api/PX_Questions/Save', mythis.Form);
                        } else {
                            //验证失败
                            showMessage(msg.NoMust, 'error');
                            return false;
                        }
                    });
                },
                getData: function () {
                    getData(this, '/api/PX_Questions/get?id=' + this.id);
                    this.Form.Courseware = this.Form.Courseware + "";
                },

                UserInput: function (val, id) { DialogShow(this, val, "QuestionManagementOptionInput.html", id); },

            },
            mounted: function () {
                var list = getDicDataArray(['题目类型', '题目等级']);
                this.QuestionManagementTypeList = list[0].value;
                this.DegreeOfDifficultyList = list[1].value;
                //this.Courseware = getDicData('n91');//编辑人;
                // this.QuestionManagementOptionsList = getDicData('50', list);


                this.options = fn(this.mydata, "0");
                var mythis = this;
                myAjax("post", this, '/api/PX_Course/GetListForDropDown', {
                    limit: 10, model: { createFactory: parent.app.formInline.model.createFactory }, offset: 0
                }, function (response) {
                    mythis.Courseware = response.data.pageData;
                }, false);

                this.id = getUrlParam("id");
                this.getData();

                if (this.Form.pX_QuestionsOptions == null) {
                    this.Form.pX_QuestionsOptions = [];
                }
            }
        });
    </script>
</body>

</html>